package org.libermundi.theorcs.security.tapestry.pages.sns;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.util.TextStreamResponse;
import org.libermundi.theorcs.core.tapestry.base.BasePageImpl;
import org.libermundi.theorcs.core.tapestry.services.AppHelper;
import org.libermundi.theorcs.core.tapestry.services.configuration.ApplicationConfig;
import org.libermundi.theorcs.security.SecurityConstants;

public class JSGigya extends BasePageImpl {
	public static final String PAGE_ID = "security.pages.sns.jsgigya";
	
	public static final String GET_JS_EVENT="getjs";
	
	@Inject
	private ApplicationConfig _appConfig;

	@Inject
	private AppHelper _appHelper;
	
	@OnEvent(value=GET_JS_EVENT)
	public StreamResponse getJS() {
		StringBuilder insert = new StringBuilder();
		
		insert.append("var gigyaConf={");
		insert.append("	APIKey: '" + _appConfig.getString(SecurityConstants.GIGYA_API_KEY) + "',");
		insert.append(" newUsersPendingRegistration: true,");
		insert.append(" lastLoginIndication: 'welcome',");
		insert.append(" lang: '" + _appHelper.getCurrentLocale().getLanguage() + "'");
		insert.append("};");

		return new TextStreamResponse("text/javascript", "utf-8", insert.toString());
	}

	/* (non-Javadoc)
	 * @see org.libermundi.theorcs.core.tapestry.BasePage#getPageId()
	 */
	@Override
	public String getPageId() {
		return PAGE_ID;
	}
}
